package com.kk.travel.dao.impl;

import java.util.List;

import com.kk.travel.admin.User;
import com.kk.travel.dao.DAO;
import com.kk.travel.dao.UserDao;

public class UserDaoImpl extends DAO<User> implements UserDao{
	
	/**
	 * 
	 *	添加user
	 *
	 * @param user
	 */
	public void InsertUser(User user){
		String sql="insert into kk_user(username,email,password) values(?,?,?)";
		update(sql, user.getUsername(),user.getEmail(),user.getPassword());
	}
	
	/**
	 * 
	 *	根据id返回User
	 *
	 * @param id
	 * @return
	 */
	public User getUserById(Integer id){
		String sql="select * from kk_user where id=?";
		return get(sql, id);
	}
	
	/**
	 * 
	 *	根据id删除User数据
	 *
	 * @param id
	 */
	public void deleteUserByid(Integer id){
		String sql="delete from kk_user where id=?";
		update(sql, id);
	}
	
	/**
	 * 
	 *	通过id修改User信息
	 *
	 * @param id
	 */
	public void ModifyUserById(User user){
		String sql="update kk_user set username=?,email=?,password=?,words=? where id=?";
		update(sql, user.getUsername(),user.getEmail(),user.getPassword(),user.getWords(),user.getId());
	}
	
	/**
	 * 通过username或者email查找用户(id)
	 * @param name
	 * @param mail
	 * @return
	 */
	public Integer getNameOrEmail(String name,String mail){
		String sql="select id from kk_user where username=? or email=?";
		return getForValue(sql,name,mail);	
	}
	
	
	/**
	 * 验证用户 账号密码
	 * @param user
	 * @return
	 */
	public User getUser(User user){
		String sql="select * from kk_user where (username=? or email=?) and password=?";
		return get(sql, user.getUsername(),user.getEmail(),user.getPassword());
	}

	/**
	 * 得到所有用户
	 */
	@Override
	public List<User> getList() {
		String sql="select * from kk_user where (username=? or email=?) and password=?";
		return getForList(sql);
	}





}
